from PyQt5.QtMultimediaWidgets import QVideoWidget
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QListWidget, QListWidgetItem, QMainWindow
from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
from PyQt5.QtCore import QUrl
import sys

class VideoPlayer(QWidget):
    def __init__(self, video_file):
        super().__init__()
        self.layout = QVBoxLayout(self)
        self.video_widget = QVideoWidget()
        self.layout.addWidget(self.video_widget)

        self.media_player = QMediaPlayer()
        self.media_player.setVideoOutput(self.video_widget)

        media_content = QMediaContent(QUrl.fromLocalFile(video_file))
        self.media_player.setMedia(media_content)
        self.media_player.play()
class test(QMainWindow):
    def __init__(self):
        super().__init__()
        layout = QVBoxLayout()

        # 创建QListWidget
        list_widget = QListWidget()

        # 创建VideoPlayer对象并添加到QListWidget中
        video_player = VideoPlayer(r"C:\Users\ChenDong\Desktop\backup\Project\PyCharm\app\answer\导航设计.mp4")

        list_item = QListWidgetItem()
        list_item.setSizeHint(video_player.size())
        list_widget.addItem(list_item)
        list_widget.setItemWidget(list_item, video_player)

        # 将QListWidget添加到布局中
        layout.addWidget(list_widget)

        self.central_widget = QWidget()
        self.central_widget.setLayout(layout)
        self.setCentralWidget(self.central_widget)
if __name__ == "__main__":
    app = QApplication(sys.argv)

    # 创建主窗口和布局
    window = test()

    window.show()
    sys.exit(app.exec_())